<?php

	class MY_Model extends CI_Model
	{
		var $table;
		var $start_init, $limit_init;

		function __construct()
		{
			parent::__construct();
			
			$this->start_init = 0;
			$this->limit_init = 10;
		}

		function select($start = false, $limit = false, $option = false)
		{			

			$this->db->select('*');
            $this->db->from($this->table);

			if( !$start )
			{
				$start = $this->start_init;
			}
			if( !$limit )
			{
				$limit = $this->limit_init;
			}

			if( $option )
			{
				foreach ($option as $key => $value) 
				{
					$this->db->where($key,$value);
				}
			}

			$this->db->limit($limit,$start);

			$query = $this->db->get();

			return $query->result();
		}
		
		function selectJoinTable($field = '', $jointable = '',$joincondition = '',$condition = '')
		{
			$this->db->select($field);
			$this->db->from($this->table);
			$this->db->join($jointable, $joincondition);
			$this->db->where($condition);
			
			$query = $this->db->get();
			
			return $query->result();
		}

		function insert($data)
		{
			$this->db->insert($this->table, $data);
		}

		function update($data, $condition)
		{
			$this->db->where($condition['name'],$condition['value']);
			$this->db->update($this->table, $data);
		}

		function delete($condition)
		{
			$this->db->where($condition['name'],$condition['value']);
			$this->db->delete($this->table);
		}

	}

?>